package dilmaj.shared;

import java.util.*;

import com.google.gwt.user.client.rpc.IsSerializable;

import dilmaj.client.TermJDO;

public class TermVO implements IsSerializable {
	private String caption;
	private Long rank;
	private Long privilege;
	private Long id;
	private Long userId;
	private String userName;
	private List<Long> areaIDs=new ArrayList<Long>();
	private List<String> userNames=new ArrayList<String>();
	private String suggestion="";
	private String useCase="";
	private List<Long> comments=new ArrayList<Long>();
	
	public TermVO(TermJDO termJDO) {
		id=termJDO.getId();
		
		if (termJDO.getCaption()==null)
			caption="";
		else
			caption=termJDO.getCaption();
		
		if (termJDO.getRank()==null) {
			rank=Long.valueOf(0);
		} else {
			rank=termJDO.getRank();
		}
		
		if (termJDO.getPrivilege()==null) {
			privilege=Long.valueOf(0);
		} else {
			privilege=termJDO.getPrivilege();
		}
		
		if (termJDO.getUserId()==null)
			userId=new Long(0);
		else
			userId=termJDO.getUserId();
		
		if (termJDO.getUserName()==null)
			userName="";
		else
			userName=termJDO.getUserName();
		
    	if (termJDO.getSuggestion()==null)
    		suggestion="";
    	else
    		suggestion=termJDO.getSuggestion();
    	
    	if (termJDO.getUseCase()==null)
    		useCase="";
    	else
    		useCase=termJDO.getUseCase();
    	
		areaIDs.clear();
		areaIDs.addAll(termJDO.getAreas());
    	
    	userNames.clear();
    	userNames.addAll(termJDO.getUsers());
    	
    	comments.clear();
    	comments.addAll(termJDO.getComments());
	}
	
	public TermVO(String caption, long rank) {
		this.caption=caption;
		this.rank=rank;
	}
	
	public TermVO(Long id, String caption, long rank) {
		this.id=id;
		this.caption=caption;
		this.rank=rank;
	}
	
	public TermVO() {
		
	}
	
	public String getCaption() {
		return caption;
	}
	
	public Long getRank() {
		return rank;
	}
	
	public void setRank(long newRank) {
		rank=newRank;
	}
	
	public void setPrivilege(long newPrivilege) {
		privilege=newPrivilege;
	}
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id=id;
	}
	
	public Long getUserId() {
		return userId;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public void setUserId(Long id) {
		this.userId=id;
	}
	
	public void setUserName(String username) {
		this.userName=username;
	}
	
	public List<Long> getAreas() {
		return areaIDs;
	}
	
	public void setAreas(List<AreaVO> areas) {
		areaIDs.clear();
		
		Iterator iterator=areas.iterator();
		while (iterator.hasNext()) {
			AreaVO currentArea=(AreaVO)iterator.next();
			areaIDs.add(currentArea.getId());
		}
	}
	
	public String getSuggestion() {
		return suggestion;
	}
	
	public String getUseCase() {
		return useCase;
	}
	
	public void setSuggestion(String suggestion) {
		this.suggestion=suggestion;
	}
	
	public void setUseCase(String useCase) {
		this.useCase=useCase;
	}
	
	public Long getPrivilege() {
		return privilege;
	}
	
	public List<String> getUsers() {
		return userNames;
	}
	
	public List<Long> getComments() {
		return comments;
	}
	
	public void addUser(String username) {
		userNames.add(username);	
	}
	
	public void addComment(CommentVO commentVO) {
		comments.add(commentVO.getId());
	}
}
